<?php
namespace Wap\Controller;
use Think\Controller;
class BaseController extends Controller {
	
	public static $wx;//缓存微信对象
	protected function _initialize(){

		if(!strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger")){
			//$this->diemsg(0,'请使用微信浏览器访问本应用！');
		}
		
		$options['appid']=C('BB_APPID_client');
		$options['secret']=C('BB_SECRET_client');
		self::$wx=new \bb\Wechat($options);
		
		if(I('code')){
			$d=self::$wx->getOauthAccessToken();
			$u=self::$wx->user($d['openid']);
			if($u['subscribe']){
				$user=self::$wx->getOauthUserInfo($d['access_token'],$d['openid']);
				if($user['openid']){
					$_SESSION['wxuser']=$user;
					$_SESSION['set']['url']=C('BB_URL');
					//已关注的微信会员信息
					p($user);
				}else{
					$url=$this->snsapi_base();
					header("location:".$url);
				}
			}else{
				//$this->redirect(U('Wap/Baseoa/index'));
				echo '没有关注！';
			}
			
		}else{
			$url=$this->snsapi_base();
			header("location:".$url);
		}
	}
	//静默授权URl
	public function snsapi_base(){
		return self::$wx->getOAuthRedirect(C('BB_URL').'/wap','xybingbing');
	}
	//停止不动的信息通知页面处理
	public function diemsg($status,$msg){
		//成功为1，失败为0
		$status=$status?$status:'0';
		$this->assign('status',$status);
		$this->assign('msg',$msg);
		$this->display('Base_diemsg');
		die();
	}
}